﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace aprendiendoHilos
{
    public partial class Form1 : Form
    {
        public delegate void testDelegate();
        private Thread hilo;
        public Form1()
        {
            InitializeComponent();
            darle();
        }
        private void darle()
        {
            this.hilo = new Thread(ejecutarHilo);
            this.hilo.Start();

        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void ejecutarHilo()
        {

            for (int i = 0; i < 5; i++)
            {
            if (label1.InvokeRequired)
            {
                label1.BeginInvoke(new testDelegate(ejecutarHilo));
            }
            else
            {
                
                    if (i % 2 == 0)
                    {
                        this.label1.Text = "Straight edge "+i;
                        this.label1.Refresh();
                    }
                    else
                    {
                        this.label1.Text = "4ever "+i;
                        this.label1.Refresh();
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(1));


                }
            }

        }

    }

}